
pub mod num {

    use std::io;
    use std::cmp::Ordering;
    use rand::Rng;

    #[test]
    fn guess() {
        println!("请输入猜测的数字");

        let mut gues = String::new();
        io::stdin().read_line(&mut gues).expect("出错了");

        println!("你猜的是：{}", gues);
    }

    #[test]
    fn rand_guess() {
        println!("请输入猜测的数字");

        let security_num = rand::thread_rng().gen_range(1, 101);

        println!("真实的数字:{}", security_num);

        let mut gues = String::new();
        io::stdin().read_line(&mut gues).expect("出错了");

        println!("你猜的是：{}", gues);
    }

    pub fn loop_guess() {
        println!("猜测的数字");

        let security_num = rand::thread_rng().gen_range(1, 101);

        loop {
            println!("请输入猜测的数字");
            let mut gue = String::new();

            io::stdin().read_line(&mut gue).expect("出错了");

            let gue : u32 = match gue.trim().parse() {
                Ok(num) => num,
                Err(_) => continue,
            };
            println!("你猜测的数字：{}", gue);

            match gue.cmp(&security_num) {
                Ordering::Less => println!("too small"),
                Ordering::Greater => println!("too big"),
                Ordering::Equal => {
                    println!("你猜对了：{}", gue);
                    break;
                }
            }
        }
    }
}